<?php
require_once("apios.php");
function qq_login($appkey,$appid, $scope, $callback,$code,$SOHT,$janeappid,$apiurl,$apikey){
    $janeqq['state'] = md5("huachi");
    if($code!=$janeqq['state']){
    	exit("请重试");
    }
    if($janeappid !="" || $apiurl !="" || $apikey!=""){
        $appid      = $janeappid;
        $callback   = "http://".$apiurl."/api/qq/qq_callback.php";
        $appkey     = $apikey;
    }

    setcookie("HOST",$SOHT);
    setcookie("janesid",$appid);
    setcookie("janeskey",$appkey);
    setcookie("callback",$callback);

    $login_url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=" 
        . $appid . "&redirect_uri=" . urlencode($callback)
        . "&state=" . $janeqq['state']
        . "&scope=".$scope;
    header("Location:$login_url");
}
header("Content-Type:text/html;charset=utf-8");

if($_GET['type'] == 'admin'){
	setcookie("TYPE",'admin');
}else if($_GET['type'] == 'shanghu'){
	setcookie("TYPE",'shanghu');
}else if($_GET['type'] == 'supindex'){
	setcookie("TYPE",'supindex');
}else if($_GET['type'] == 'supadmin'){
	setcookie("TYPE",'supadmin');
}else if($_GET['type'] == 'vipadmin'){
	setcookie("TYPE",'vipadmin');
}else if(($_GET['type'] == 'build')){
	setcookie("TYPE",'build');
  	setcookie("BUILD",$_GET['id']);
  	setcookie("FROM",$_GET['from']);
}else if(($_GET['type'] == 'shbuild')){
	setcookie("TYPE",'shbuild');
  	setcookie("BUILD",$_GET['id']);
  	setcookie("FROM",$_GET['from']);
}else if(($_GET['type'] == 'supbuild')){
	setcookie("TYPE",'supbuild');
  	setcookie("BUILD",$_GET['id']);
  	setcookie("FROM",$_GET['from']);
}else if(($_GET['type'] == 'supindexbuild')){
	setcookie("TYPE",'supindexbuild');
  	setcookie("BUILD",$_GET['id']);
  	setcookie("FROM",$_GET['from']);
}else if(($_GET['type'] == 'skbs')){
	setcookie("TYPE",'skbs');
}
else{
	setcookie("TYPE",'',-1);
}


$HOST        = base64_decode(isset($_GET['HOST'])?htmlspecialchars($_GET['HOST']):'jane');       //回调地址
$appid       = base64_decode(isset($_GET['appid'])?htmlspecialchars($_GET['appid']):0);          //外包商户appid
$apiurl      = base64_decode(isset($_GET['apiurl'])?htmlspecialchars($_GET['apiurl']):0);        //外包商户回调地址
$apikey      = base64_decode(isset($_GET['apikey'])?htmlspecialchars($_GET['apikey']):0);        //外包商户apikey
qq_login($janeqq["appkey"],$janeqq["appid"], $janeqq["scope"], $janeqq["callback"],isset($_GET['code'])?$_GET['code']:"Jane",$HOST,$appid,$apiurl,$apikey);
?>
